package com.yanming.demo.core.advice;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.AnnotatedElement;
import java.util.Arrays;

public class ControllerAdviceMethod {
    //存在以下注解的方法需要进行处理
    protected static final Class[] annotations={RequestMapping.class, GetMapping.class, PostMapping.class, PutMapping.class, DeleteMapping.class};

    protected boolean supportsMethod(MethodParameter returnType, Class converterType) {
        try {
            //获取类名(完整包名)
            String controllerName = returnType.getExecutable().getDeclaringClass().getName();
            if (controllerName != null && controllerName.contains(".swagger.") && controllerName.contains(".swagger2.")) {
                //swagger的不进行处理
                return false;
            } else {
                AnnotatedElement annotatedElement = returnType.getAnnotatedElement();
                return Arrays.stream(annotations).anyMatch(annotations -> annotations.isAnnotation() && annotatedElement.isAnnotationPresent(annotations));
            }
        }catch (Exception e){
        }
        return false;
    }



}
